home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / graphics 2d / makeicon / oldbitmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  2.9 KB  |  88 lines

  1. /*
  2.     File:        OldBitMap.c
  3.  
  4.     Contains:    old-style bitmap utility routines for allocating, de-allocating, and masking.
  5.  
  6.     Written by:     
  7.  
  8.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/9/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. #include "OldBitMap.h"
  24. #include <Quickdraw.h>
  25. #include <Memory.h>
  26.  
  27. void FreeBitMap(BitMap *Bits)
  28. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29.     Dumps a BitMap created by NewBitMap below.
  30.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  31. {
  32.     DisposePtr(Bits->baseAddr);
  33.     Bits->baseAddr=nil;
  34.     SetRect(&Bits->bounds,0,0,0,0);
  35.     Bits->rowBytes=0;
  36. }
  37.  
  38. void CalcOffScreen(register Rect *frame,register long *needed, register short *rows)
  39. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40.     Calculates how much memory and rowbytes a bitmap of the size frame would require.
  41.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  42. {
  43.     *rows=((((frame->right) - (frame->left)) + 15)/16) *2;
  44.     *needed=(((long)(*rows)) * (long)((frame->bottom) - (frame->top)));
  45. }
  46.  
  47. void NewBitMap(Rect *frame,BitMap *theMap)
  48. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  49.     Creates a new empty bitmap.
  50.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  51. {
  52.     Size    size;
  53.     short    rbytes;
  54.     
  55.     CalcOffScreen(frame,&size,&rbytes);
  56.     
  57.     theMap->rowBytes=rbytes;
  58.     theMap->bounds=*frame;
  59.     theMap->baseAddr=NewPtrClear(size);
  60. }
  61.  
  62.  
  63. void NewMaskedBitMap(BitMap    *srcBits, BitMap *maskBits, Rect *srcRect)
  64. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65.     Pass a pointer to an existing bitmap, and this creates a bitmap that is an
  66.     equivelent mask.
  67.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  68. {
  69.     short    rowbytes,height,words;
  70.     long    needed;
  71.  
  72.     NewBitMap(srcRect,maskBits);
  73.     
  74.     if(MemError())        
  75.     {
  76.         maskBits->baseAddr=nil;
  77.          SetRect(&maskBits->bounds,0,0,0,0);
  78.          maskBits->rowBytes=0;
  79.      }
  80.      else        /*    memory was allocated for Mask BitMap ok */
  81.      {
  82.          CalcOffScreen(srcRect,&needed,&rowbytes);
  83.          words=rowbytes/2;
  84.          height=srcRect->bottom - srcRect->top;
  85.          CalcMask(srcBits->baseAddr,maskBits->baseAddr,rowbytes,rowbytes,height,words);
  86.      }
  87. }
  88.